package com.wfy.service;

import com.wfy.mapper.CategoryMapper;
import com.wfy.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;

/**
 * @Title: CategoryService
 * @Package com.wfy
 * @Author 王飞遥
 * @Date 2022/8/16 22:38
 */
@Service
public class CategoryService {
    @Autowired
    CategoryMapper categoryMapper;
    public List<Category> queryCategoryList(Long pid) {
        Category category = new Category();
        category.setParentId(pid);
        //引入了tk.mapper
        //如果你new一个对象,并且对对象中的某一个字段或者多个字段赋值
        //然后你执行select方法的时候,他会通过你传入的对象中的值或多个值 进行and拼接
        //select * from tb_category where parent_id=?
        return categoryMapper.select(category);
    }

    public List<String> queryNamesByIds(List<Long> cids) {
        ArrayList<String> list = new ArrayList<>();
        for (Long cid : cids) {
            Category category = categoryMapper.selectByPrimaryKey(cid);
            list.add(category.getName());
        }
        return list;
    }
}
